﻿@{
    ViewBag.Title = "包仓合同";
    Layout = "~/Views/Shared/InfoMaste.cshtml";
}
<script src="~/Js/Global.js"></script>
<table id="dg" class="easyui-datagrid"  style="width:100%; height: 600px;"
       url="/LKWarehouseContract/GetLKWarehouseContractPageList" toolbar="#tb" title="包仓合同" rownumbers="true" pagination="true"
       pagelist="[15]" fitcolumns="true" singleselect="true">
    <thead>
        <tr>
            <th field="ContractNo" align="right" width="10%">
                合同编号
            </th>
            <th field="CustomerId" align="right" width="10%">
                客户
            </th>
            <th field="ContractTime" align="right" width="10%" formatter="formatter_ContractTime">
                开单日期
            </th>
            <th field="BeginTime" align="right" width="10%" formatter="formatter_BeginTime">
                开始日期
            </th>
            <th field="EndTime" align="right" width="10%" formatter="formatter_EndTime">
                结束日期
            </th>
            <th field="StoreType" align="right" width="10%">
                包仓类型
            </th>
            <th field="StoreAlgorithm" align="right" width="10%">
                包仓算法
            </th>
            <th field="UnitPrice" align="right" width="10%" formatter="formatter_UnitPrice">
                单价
            </th>
            <th field="Number" align="right" width="10%">
                数量
            </th>
            <th field="Amount" align="right" width="10%" formatter="formatter_Amount">
                总金额
            </th>
            <th field="WareHouseId" align="right" width="10%">
                仓库
            </th>
            <th field="IsValid" align="right" width="10%" formatter="formatter_IsValid">
                是否停用
            </th>
        </tr>
    </thead>
</table>
<div id="tb" style="padding: 3px; height: auto;">
    <span>合同编号</span>
    <input id="ContractCode" class="easyui-textbox " data-options="validType:'length[1,6]',prompt:'1~6位数字'" style="width: 173px; height: 30px;" />
    <span>客户名称</span>
    <input type="hidden" id="hdselectKeyword" />
    <input name="SelectCustomer" id="SelectCustomer" class="easyui-combobox" style="width: 90px; height: 30px;" />
    <span>开始时间</span>
    <input class="easyui-datebox" name="BeginTime" id="BeginTime" style="width: 173px; height: 30px; ">
    <span>结束时间</span>
    <input class="easyui-datebox" name="EndTime" id="EndTime" style="width: 173px; height: 30px; ">
    <span>状态</span>
    <select id="IsValid" class="easyui-combobox" data-options="editable:false" style="width: 90px; height: 30px;">
        <option value="" selected="selected">全部</option>
        <option value="true">启用</option>
        <option value="false">停用</option>
    </select>
    <div>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="addLKWarehouseContract()">新建</a>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editLKWarehouseContract()">编辑</a>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-no" plain="true" onclick="delLKWarehouseContract()">删除</a>
        <a href="javascript:" class="easyui-linkbutton" plain="true" iconcls="icon-search" onclick="doSearch()">查询</a>
    </div>
</div>


<script language="javascript" type="text/javascript">
    $(function () {
        InitSelectCustomer();
    });

    function addLKWarehouseContract() {
        window.location.href = "/LKWarehouseContract/AddLKWarehouseContract";
    }

    //function InitChargingUnitCombobox() {
    //    $('#ChargingUnit').combobox({
    //        url: "/LkGlobal/GetChargeUnitList",
    //        valueField: 'Value',
    //        textField: 'Description',
    //        onSelect: function (rec) {
    //            //$('#ChargingUnit').combobox("setValue", rec.Value);
    //        }
    //    });
    //}

    //function InitColdAlgorithmCombobox() {
    //    $('#ColdAlgorithm').combobox({
    //        url: "/LkGlobal/GetColdAlgorithmList",
    //        valueField: 'Value',
    //        textField: 'Description',
    //        onSelect: function (rec) {
    //            //$('#ColdStorage').combobox("setValue", rec.Value);
    //        }
    //    });
    //}
    //function checkDecimal(newValue, oldValue) {
    //    if (newValue.toString().split('.').length > 1) {
    //        var decimalPart = newValue.toString().split('.')[1];
    //        if (decimalPart.length > 2) {
    //            alert(22);
    //            //$.messager.alert('Warning', '超过两位小数！');
    //            $(this).numberbox('setValue', oldValue);
    //        }
    //    }
    //}
    //function setFixRate() {
    //    //	var value = $('._fixRate').numberbox('getValue');//不能使用numberbox的getValue,这个是隐藏框的值
    //    //如果有小数点
    //    var value = $('#Balance').val();//这个才是输入框的值
    //    if (value.indexOf(".") >= 0) {//如果包含小数点
    //        if ((value.substring(value.indexOf(".") + 1).length) >= 2) {//如果小数位数已经有两位
    //            //			window.event.returnValue = false;
    //            //			$('._fixRate').val(value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'));
    //            //			$('._fixRate').numberbox('filter',false);
    //            $('#Balance').numberbox('options').filter = function () {
    //                //让filter返回false会禁止按键输入
    //                return false;
    //            };
    //        } else {
    //            //记得写else,否则该nunberbox将不允许再次输入了
    //            $('#Balance').numberbox('options').filter = function () {
    //                return true;
    //            }
    //        }
    //    }
    //}

    function doSearch() {
        $('#dg').datagrid('load', {
            ContractNo: $('#ContractCode').val(),
            CustomerId: $('#SelectCustomer').combobox('getValue'),
            IsValid: $('#IsValid').combobox('getValue'),
            BeginTime: $('#BeginTime').datebox('getValue'),
            EndTime: $('#EndTime').datebox('getValue'),
        });
    }

    //function InitCustomer() {
    //    $('#CustomerId').combogrid({
    //        url: "/Customer/GetCustomerPageList",
    //        method: 'post',
    //        mode: 'remote',
    //        pageSize: 15,               //每页显示的记录条数，默认为10
    //        pageList: [10, 15, 20],       //可以设置每页记录条数的列表
    //        pagination: true,
    //        panelWidth: 500,
    //        toolbar: "#customerselecttoolbar2",
    //        idField: 'Id',
    //        textField: 'CustomerCode',
    //        onSelect: function () {
    //            var g = $('#CustomerId').combogrid('grid');
    //            var row = g.datagrid('getSelected');
    //            $('#CustomerId').combogrid("setValue", row.Id);
    //            $('#CustomerName').textbox('setValue', row.CustomerName);
    //        },
    //        columns: [[
    //            { field: 'Id', title: 'Id', hidden: true },
    //            { field: 'CustomerCode', title: '客户编号', width: 120, align: 'right' },
    //            { field: 'CustomerName', title: '客户名称', width: 150, align: 'right' }
    //        ]],
    //        fitColumns: true,
    //        filter: true,  // 启用搜索框
    //    });
    //}

    //function InitSelectCustomer() {
    //    $('#SelectCustomer').combogrid({
    //        url: "/Customer/GetCustomerPageList",
    //        method: 'post',
    //        mode: 'remote',
    //        pageSize: 15,               //每页显示的记录条数，默认为10
    //        pageList: [10, 15, 20],       //可以设置每页记录条数的列表
    //        pagination: true,
    //        panelWidth: 500,
    //        toolbar: "#customerselecttoolbar",
    //        idField: 'Id',
    //        textField: 'CustomerName',
    //        columns: [[
    //            { field: 'Id', title: 'Id', hidden: true },
    //            { field: 'CustomerCode', title: '客户编号', width: 120, align: 'right' },
    //            { field: 'CustomerName', title: '客户名称', width: 150, align: 'right' }
    //        ]],
    //        fitColumns: true,
    //        filter: true  // 启用搜索框
    //    });
    //}

    function querycustomer() {
        $("#SelectCustomer").combogrid("grid").datagrid("reload", { "Customer": $("#SelectCustomerText").val() });
    }
    function querycustomer2() {
        $("#CustomerId").combogrid("grid").datagrid("reload", { "Customer": $("#SelectCustomerText2").val() });
    }

    function editLKWarehouseContract() {
        var row = $('#dg').datagrid('getSelected');
        if (!row) {
            Helper.Show('请选择需要编辑的信息?');
            return;
        }
        window.location.href = "/LKWarehouseContract/EditLKWarehouseContract?id=" + row.Id;
    }

    function delLKWarehouseContract() {
        var row = $('#dg').datagrid('getSelected');
        if (!row) {
            Helper.Show('请选择需要删除的信息?');
            return false;
        }
        $.messager.confirm('提示信息', '您确认要删除吗?', function (r) {
            if (!r) { return false; }
            $.post("/LKWarehouseContract/DeleteLKWarehouseContract", { id: row.Id }, function (json) {
                Helper.Show(json.Msg);
                if (json.Success) {
                    doSearch();
                }
            });
        });
    }

    function saveLKWarehouseContract() {
        $('#fm').form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (json) {
                var json = eval('(' + json + ')');
                Helper.Show(json.Msg);
                if (json.Success) {
                    $('#fm').form('clear');
                    $('#dlg').dialog('close');
                    $('#dg').datagrid('reload');
                }
            }
        });
    }

    function formatter_IsValid(value, rowData, rowIndex) {
        return rowData.IsValid ? '启用' : '停用';
    }

    function formatter_IsByTon(value, rowData, rowIndex) {
        return rowData.IsByTon ? '是' : '否';
    }

    function formatter_Amount(value, rowData, rowIndex) {
        return rowData.Amount.toFixed(2);
    }
    function formatter_UnitPrice(value, rowData, rowIndex) {
        return rowData.UnitPrice.toFixed(2);
    }

    function formatter_BeginTime(value, rowData, rowIndex) {
        return formatdate(rowData.BeginTime);
    }
    function formatter_EndTime(value, rowData, rowIndex) {
        return formatdate(rowData.EndTime);
    }
    function formatter_ContractTime(value, rowData, rowIndex) {
        return formatdate(rowData.ContractTime);
    }

    function formatdate(value) {
        var date = new Date(value);//long转换成date
        var year = date.getFullYear().toString();
        var month = (date.getMonth() + 1);
        var day = date.getDate().toString();
        if (month < 10) {
            month = "0" + month;
        }
        if (day < 10) {
            day = "0" + day;
        }
        return year + "-" + month + "-" + day;
    }
</script>



